﻿using System.Web;
using ZLDC.Common.Estate;
using System;

namespace ZLDC.Estate
{
    public class CHandlerIndex
    {        
                                        public static void ChooseMethod()
        {
               
            string act = _Request.GetString("act", "");            

            switch (act)
            {
                #region 片区管理
                case "area_list":
                    AreaList();
                    break;
                case "area_save":
                    AreaSave();
                    break;
                case "area_save1":
                    AreaSave1();
                    break;
                case "area_del":
                    AreaDel();
                    break;
                case "department_area_add":
                    DepartmentAreaAdd();
                    break;
                case "department_estate_add":
                    DepartmentEstateAdd();
                    break;

                #endregion

                #region 楼盘字典管理

                case "estate_save":
                    EstateSave();
                    break;
                case "estate_list":
                    EstateList();
                    break;
                case "estate_list_action":
                    EstateListAction();
                    break;
                case "estate_list_action1":
                    EstateListAction1();
                    break;
                case "estate_detail":
                    EstateDetail();
                    break;
                case "estate_del":
                    EstateDel();
                    break;

                case "estate_delall":
                    EstateDelAll();                                 break;                    

                case "HousingMS_Auto":
                    HousingMSAuto();                                break;                    
                case "estate_auto_list":
                    EstateAutoList();                               break;
                case "no_estate_auto_list":
                    NoEstateAutoList();                             break;

                case "all_estate_auto_list":
                    AllEstateAutoList();                             break;                     

                case "build_auto_list":
                    BuildAutoList();                                break;
                case "build_auto_newlist":
                    BuildAutoNewList();                                break;
                case "build_auto_list_string":
                    BuildAutoListString();                          break;  
                case "Ename_Auto_ListString":
                    EnameAutoListString();                          break;
                case "buildlist_byeid":
                    buildlist_byeid();                              break;

                case "p_Estate_Recycle_List":
                    p_Estate_Recycle_List();
                    break;
                case "p_Build_Recycle_List":
                    p_Build_Recycle_List();
                    break;
                case "DeleteBuild":
                    DeleteBuild();
                    break;
                case "DeleteBuildAndIsValid":
                    BuildDelAndIsValid();
                    break;
                case "DeleteEstate":
                    DeleteEstate();
                    break;
                case "UpdateBuildDelFlag":
                    UpdateBuildDelFlag();
                    break;
                case "UpdateEstateDelFlag":
                    UpdateEstateDelFlag();
                    break;
                case "DelPic":
                    DelPic();
                    break;
                case "UpdateBuild":                    UpdateBuild();
                    break;
                case "UpdateBuildParentId":
                    UpdateBuildParentId();
                    break;
                case "RemoveBuildParentId":
                    RemoveBuildParentId();
                    break;

                case "upateEstate":
                    UpateEstate();
                    break;

                #endregion

                #region 栋阁管理

                case "build_list":
                    BuildList();
                    break;
                case "Build_ListByName":
                    BuildListByName();
                    break;
                case "buildlist_ByEname":
                    buildlist_ByEname();
                    break;
                case "build_save":
                    BuildSave();
                    break;
                case "build_detail":
                    BuildDetail();
                    break;     
                case "SelectNamesById":
                    SelectNamesById();
                    break;
                case "SelectNamesByBId":
                    SelectNamesByBId();
                    break;
                case "build_del":
                    BuildDel();
                    break;
                    
                #endregion

                #region 房号管理
                case "roomno_del":
                    RoomnoDel();
                    break;
                case "roomno_isvalid_del":
                    RoomnoDelAndIsValid();
                    break;
                case "RemoveRoomNoByBId":                    RemoveRoomNoByBId();
                    break;
                #endregion

                #region 楼盘图片
                case "estatepic_list":
                    EstatePicList();
                    break;

                #endregion
            }
        }

        #region 片区管理

                                private static void AreaList()
        {
            int parentid = _Request.GetInt("parentid", 0);

            string json = ZLDC.Topo.BLL.Estate.AreaBLL.AreaList(parentid);

            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write(json);
            HttpContext.Current.Response.End();
        }

                                private static void AreaSave()
        {
            int id = _Request.GetInt("id", 0);    
            string name = _Request.GetString("name", "");
            string namePy = "";             int parentid = _Request.GetInt("parentid", 0);
            int delflag = _Request.GetInt("delflag", 0);
            int ord = _Request.GetInt("ord", 0);

            string outmsg = ZLDC.Topo.BLL.Estate.AreaBLL.AreaSave(id, name, namePy, parentid, delflag, ord);

            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write(outmsg);
            HttpContext.Current.Response.End();
        }

                                private static void AreaDel()
        {
            int id = _Request.GetInt("id", 0);

            string outmsg = ZLDC.Topo.BLL.Estate.AreaBLL.AreaDel(id);

            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write(outmsg);
            HttpContext.Current.Response.End();
        }

                                private static void DepartmentAreaAdd()
        {
            bool isadd = _Request.GetBool("isadd", false);              int areaid = _Request.GetInt("areaid", 0);
            int deptid = _Request.GetInt("deptid", 0);

            string outmsg = "";
            
                        ZLDC.Topo.Model.Estate.AuthorizationInfo info = ZLDC.Topo.BLL.Estate.AuthorizationBLL.p_authorization_detail(deptid);

            if (ZLDC.Common.Estate._Tools.IsExistsStr(info.Areas, areaid.ToString()))
                outmsg = "该片区已存在,不能重复添加!";
            else
            {
                if (isadd)
                    outmsg = ZLDC.Topo.BLL.Estate.AuthorizationBLL.p_authorization_delete(3, deptid, areaid.ToString());
                else
                    outmsg = ZLDC.Topo.BLL.Estate.AuthorizationBLL.p_authorization_delete(1, deptid, areaid.ToString());
            }

            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write(outmsg);
            HttpContext.Current.Response.End();
        } 
       
                                private static void DepartmentEstateAdd()
        {
            bool isadd = _Request.GetBool("isadd", false);              int estateid = _Request.GetInt("estateid", 0);
            int deptid = _Request.GetInt("deptid", 0);

            string outmsg = "";

                        ZLDC.Topo.Model.Estate.AuthorizationInfo info = ZLDC.Topo.BLL.Estate.AuthorizationBLL.p_authorization_detail(deptid);

            if (ZLDC.Common.Estate._Tools.IsExistsStr(info.Estates, estateid.ToString()))
                outmsg = "该楼盘已存在,不能重复添加!";
            else
            {
                if (isadd)
                    outmsg = ZLDC.Topo.BLL.Estate.AuthorizationBLL.p_authorization_delete(4, deptid, estateid.ToString());
                else
                    outmsg = ZLDC.Topo.BLL.Estate.AuthorizationBLL.p_authorization_delete(2, deptid, estateid.ToString());
            }

            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write(outmsg);
            HttpContext.Current.Response.End();
        }         

        #endregion

        #region 楼盘字典管理

                                private static void EstateSave()
        {
            int registerUserid = _Convert.ToInt(_Utility.GetInfoBySession().m_sUserID, 0);
            string registerName = _Utility.GetInfoBySession().m_sUserName;                              int registerDeptid = _Convert.ToInt(_Utility.GetInfoBySession().m_sDeptID, 0);
            string registerDept = _Utility.GetInfoBySession().m_sDeptName;

            int ActionType = _Request.GetIntForm("ActionType", 0);            int CommandId = _Request.GetIntForm("CommandId", 0);

            int id = _Request.GetIntForm("hID", 0);
            string name = _Request.GetStringForm("iName", "");                                      string roadName = _Request.GetStringForm("iRoadName", "");                              string namePy = _Utility.GetChineseSpell(name);                                         string otherName = _Request.GetStringForm("iOtherName", "");                            string otherNamePy = _Utility.GetChineseSpell(otherName);                               int cityId = _Request.GetIntForm("hCityId", 0);                                         int areaId = _Request.GetIntForm("hAreaId", 0);                                         string address = _Request.GetStringForm("iAddress", "");                                string aroundCondition = _Request.GetStringForm("hAroundCondition", "");                string usage =_Request.GetStringForm("sUsage", "");                                    string type = _Request.GetStringForm("sType", "");                                      string propertyCompany = _Request.GetStringForm("iPropertyCompany", "");                string description = _Request.GetStringForm("taDescription", "");                       string propertyTel = _Request.GetStringForm("iPropertyTel", "");                        string propertyLevel = _Request.GetStringForm("sPropertyLevel", "");                    string completeDate = _Request.GetStringForm("iCompleteDate", "");                      string trafficCondition = _Request.GetStringForm("taTrafficCondition", "");             float constructionArea = _Request.GetFloatForm("iConstructionArea", 0);                 int familyTotal = _Request.GetIntForm("iFamilyTotal", 0);                               string construction = _Request.GetStringForm("iConstruction", "");                      string remark = _Request.GetStringForm("taRemark", "");                                 float salesFare = _Request.GetFloatForm("iSalesFare", 0);                               float propertyFare = _Request.GetFloatForm("iPropertyFare", 0);                         string realestateName = _Request.GetStringForm("iRealestateName", "");                  string realestateTel = _Request.GetStringForm("iRealestateTel", "");                    string updateName = registerName;                                                       int isvalid = 4;                  string leaseTime = _Request.GetStringForm("LeaseTime", "");                              string park = _Request.GetStringForm("park", "");                           
            int companyId = _Convert.ToInt(_Utility.GetWebConfigSetting("companyId"), 1);   
                        if (ZLDC.Common.BaseUser.UserInfo.GetPopedom("直接添加楼盘"))
            {
                if (companyId == 1)
                {
                    isvalid = 0;
                }
                else
                {
                    isvalid = 3;
                }
            }
            if (ActionType == 0)            {
                string outmsg = ZLDC.Topo.BLL.Estate.EstateBLL.EstateSave(id, name, roadName, otherName, namePy, otherNamePy, cityId, "", areaId, "", address, usage,
                    type, constructionArea, construction, salesFare, familyTotal, propertyLevel, propertyCompany, propertyTel, propertyFare, realestateName,
                    realestateTel, registerUserid, registerName, registerDeptid, registerDept, updateName, aroundCondition, trafficCondition, remark, completeDate, isvalid, leaseTime, park);
                _Utility.GoError(outmsg);

            }
            else if(ActionType==1 || ActionType==2)             {
                string newidoroutmsg = ZLDC.Topo.BLL.Estate.EstateBLL.EstateSaveAndBuildName(id, name, roadName, otherName, namePy, otherNamePy, cityId, "", areaId, "", address, usage,
                    type, constructionArea, construction, salesFare, familyTotal, propertyLevel, propertyCompany, propertyTel, propertyFare, realestateName,
                    realestateTel, registerUserid, registerName, registerDeptid, registerDept, updateName, aroundCondition, trafficCondition, remark, completeDate, isvalid, leaseTime, park);
                string[] strs = newidoroutmsg.Split(',');
                string newid = strs[0].ToString();
                string outmsg = strs[1].ToString();
                if (outmsg != "" && newid=="0") 
                {
                    _Utility.GoError(outmsg);
                }
                if(ActionType==1)
                    HttpContext.Current.Response.Redirect("../TM/BuildAdd.aspx?id=0&eid=" + newid + "&typeid="+CommandId+"");                else
                    HttpContext.Current.Response.Redirect("../TM/BatchBuildRoom.aspx?eid=" + newid + "&typeid=" + CommandId + "");                            }
        }

                private static void p_Estate_Recycle_List() 
        {
            int page = _Request.GetInt("page", 0);
            int pagesize = _Request.GetInt("pagesize", 0);
            int eId = _Request.GetInt("eId", 0);
            string eName = _Request.GetString("eName", "");
            string condition = " where delflag= 1 ";
            if (eId > 0)
                condition += " id=" + eId + "";
            if (eName != "")
                condition += " name='" + eName + "'";



            string json = ZLDC.Topo.BLL.Estate.EstateBLL.EstateList(page, pagesize, condition);

            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write(json);
            HttpContext.Current.Response.End();

        }

                private static void p_Build_Recycle_List() 
        {
            int page = _Request.GetInt("page", 0);
            int pagesize = _Request.GetInt("pagesize", 0);
            string condition = " where delflag= 1 ";
            string json = ZLDC.Topo.BLL.Estate.BuildBLL.p_build_recycle_list_table(page, pagesize, condition);

            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write(json);
            HttpContext.Current.Response.End();

        }

                public static void DeleteEstate()
        {
            string outmsg = "";
            string[] IDList = _Utility.GetStringBySplit(_Request.GetString("id"), '|');

            if (IDList != null && IDList.Length > 0)
            {
                for (int i = 0; i < IDList.Length; i++)
                {
                    outmsg = ZLDC.Topo.BLL.Estate.EstateBLL.DeleteEstate(_Convert.ToInt(IDList[i], 0));
                }
            }

            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write(outmsg);
            HttpContext.Current.Response.End();
        }

                public static void DeleteBuild()
        {
            string outmsg = "";
            string[] IDList = _Utility.GetStringBySplit(_Request.GetString("id"), '|');

            if (IDList != null && IDList.Length > 0)
            {
                for (int i = 0; i < IDList.Length; i++)
                {
                    outmsg = ZLDC.Topo.BLL.Estate.BuildBLL.DeleteBuild(_Convert.ToInt(IDList[i], 0));
                }
            }

            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write(outmsg);
            HttpContext.Current.Response.End();
        }

                public static void UpdateBuildDelFlag()
        {
            string outmsg = "";
            string[] IDList = _Utility.GetStringBySplit(_Request.GetString("id"), '|');

            if (IDList != null && IDList.Length > 0)
            {
                for (int i = 0; i < IDList.Length; i++)
                {
                    outmsg = ZLDC.Topo.BLL.Estate.BuildBLL.UpdateDelFlag(_Convert.ToInt(IDList[i], 0));
                }
            }

            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write(outmsg);
            HttpContext.Current.Response.End();
        }

                public static void UpdateEstateDelFlag()
        {
            string outmsg = "";
            string[] IDList = _Utility.GetStringBySplit(_Request.GetString("id"), '|');

            if (IDList != null && IDList.Length > 0)
            {
                for (int i = 0; i < IDList.Length; i++)
                {
                    outmsg = ZLDC.Topo.BLL.Estate.EstateBLL.UpdateDltFlag(_Convert.ToInt(IDList[i], 0));
                }
            }

            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write(outmsg);
            HttpContext.Current.Response.End();
        }

                                private static void EstateList()
        {
            int userid = _Convert.ToInt(_Utility.GetInfoBySession().m_sUserID, 0);
            int deptId = _Convert.ToInt(_Utility.GetInfoBySession().m_sDeptID);
            string station = _Utility.GetInfoBySession().m_sStation;            
            int page = _Request.GetInt("page", 0);
            int pagesize = _Request.GetInt("pagesize", 0);
            int build = _Request.GetInt("build", 0);
            int areaid = _Request.GetInt("areaid", 0);
            string name = _Request.GetString("name", "");

            string condition = " where delFlag=0 and isValid=0 ";

                        if (!ZLDC.Common.BaseUser.UserInfo.GetPopedom("查看全部盘源"))
            {
                condition += " and " + ZLDC.Topo.BLL.Estate.EstateBLL.GetAreaByDeptId(deptId);
            }

            if (areaid > 0)
                condition += " and areaId=" + areaid;
            else
            {
                if (build > 0)
                    condition += " and cityId = " + build;
            }

            if (!string.IsNullOrEmpty(name))
                condition += " and (name like '" + name + "%' or otherName like '" + name + "%' or namePy like '" + name + "%' or otherNamePy like '" + name + "%')";

            string json = ZLDC.Topo.BLL.Estate.EstateBLL.EstateList(page, pagesize, condition);

            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write(json);
            HttpContext.Current.Response.End();
        }

                                private static void EstateListAction()
        {            
            int userid = _Convert.ToInt(_Utility.GetInfoBySession().m_sUserID, 0);
            int deptId = _Convert.ToInt(_Utility.GetInfoBySession().m_sDeptID);
            string station = _Utility.GetInfoBySession().m_sStation;                        int page = _Request.GetInt("page", 0);
            int pagesize = _Request.GetInt("pagesize", 0);
            int build = _Request.GetInt("build", 0);                        int areaid = _Request.GetInt("areaid", 0);                      string name = _Request.GetString("name", "");       
            string condition = " where delFlag=0 ";

            int isvalid = _Request.GetInt("isvalid", 0);                    if (isvalid >= 0)
                condition += " and isvalid=" + isvalid;
            
                        if (!ZLDC.Common.BaseUser.UserInfo.GetPopedom("查看全部盘源"))
            {
                condition += " and " + ZLDC.Topo.BLL.Estate.EstateBLL.GetAreaByDeptId(deptId);
            }

            string dateColumns = _Request.GetString("dateColumns", "");                 string startdate = _Request.GetString("startday", "");
            string enddate = _Request.GetString("endday", "");       
            if (dateColumns != "" && startdate != "" && enddate != "")
                condition += " and " + dateColumns + " > '" + startdate + "' and " + dateColumns + " < '" + enddate + "'";

                        string usage = _Request.GetString("usage", "");
            if (usage != "" && usage != "全部" && usage != "无")
                condition += " and [usage]='" + usage + "'";

                        string type = _Request.GetString("type", "");
            if (type != "" && type != "全部" && type != "无")
                condition += " and [type]='" + type + "'";

                        string otherColumns = _Request.GetString("otherColumns", ""); 
            string otherColumnsValue = _Request.GetString("otherColumnsValue", "");
            if (otherColumns != "" && otherColumnsValue != "" )
                condition += " and " + otherColumns + " = " + otherColumnsValue;
           
            if (areaid > 0)
                condition += " and areaId=" + areaid;
            else
            {
                if (build > 0)
                    condition += " and cityId = " + build;
            }

            if (!string.IsNullOrEmpty(name))
                condition += " and (name like '" + name + "%' or otherName like '" + name + "%' or namePy like '" + name + "%' or otherNamePy like '" + name + "%')";

            string json = ZLDC.Topo.BLL.Estate.EstateBLL.EstateList(userid, page, pagesize, condition);

            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write(json);
            HttpContext.Current.Response.End();
        }

                                private static void EstateListAction1()
        {
            int userid = _Convert.ToInt(_Utility.GetInfoBySession().m_sUserID, 0);
            int deptId = _Convert.ToInt(_Utility.GetInfoBySession().m_sDeptID);
            string station = _Utility.GetInfoBySession().m_sStation;                        int page = _Request.GetInt("page", 0);
            int pagesize = _Request.GetInt("pagesize", 0);
            int build = _Request.GetInt("build", 0);                        int areaid = _Request.GetInt("areaid", 0);                      string name = _Request.GetString("name", "");       
            string condition = " where delFlag=0 and (isValid=0 or isValid=2)";

                        if (!ZLDC.Common.BaseUser.UserInfo.GetPopedom("查看全部盘源"))
            {
                condition += " and " + ZLDC.Topo.BLL.Estate.EstateBLL.GetAreaByDeptId(deptId);
            }

            string dateColumns = _Request.GetString("dateColumns", "");                 string startdate = _Request.GetString("startday", "");
            string enddate = _Request.GetString("endday", "");
            if (dateColumns != "" && startdate != "" && enddate != "")
                condition += " and " + dateColumns + " > '" + startdate + "' and " + dateColumns + " < '" + enddate + "'";

                        string usage = _Request.GetString("usage", "");
            if (usage != "" && usage != "全部" && usage != "无")
                condition += " and [usage]='" + usage + "'";

                        string type = _Request.GetString("type", "");
            if (type != "" && type != "全部" && type != "无")
                condition += " and [type]='" + type + "'";

                        string otherColumns = _Request.GetString("otherColumns", "");
            string otherColumnsValue = _Request.GetString("otherColumnsValue", "");
            if (otherColumns != "" && otherColumnsValue != "")
                condition += " and " + otherColumns + " = " + otherColumnsValue;

            if (areaid > 0)
                condition += " and areaId=" + areaid;
            else
            {
                if (build > 0)
                    condition += " and cityId = " + build;
            }

            if (!string.IsNullOrEmpty(name))
                condition += " and (name like '" + name + "%' or otherName like '" + name + "%' or namePy like '" + name + "%' or otherNamePy like '" + name + "%')";

            string json = ZLDC.Topo.BLL.Estate.EstateBLL.EstateList(userid, page, pagesize, condition);

            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write(json);
            HttpContext.Current.Response.End();
        }        

                                private static void EstateDetail()
        {
            int id = _Request.GetInt("id", 0);

            string json = ZLDC.Topo.BLL.Estate.EstateBLL.EstateDetail(id);

            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write(json);
            HttpContext.Current.Response.End();
        }

                                private static void EstateDel()
        {

            int id = 0;
            string outmsg = "";
            string[] IDList = _Utility.GetStringBySplit(_Request.GetString("id"), '|');
            string type = _Request.GetString("type", "");
            if (type == "1")
            {
                if (IDList != null && IDList.Length > 0)
                {
                    for (int i = 0; i < IDList.Length; i++)
                    {
                        id = _Convert.ToInt(IDList[i], 0);
                        outmsg = ZLDC.Topo.BLL.Estate.EstateBLL.EstateDel(id);

                        ZLDC.Topo.BLL.Estate.OperationlogBLL.p_operationlog_insert("t_estate", id, 2, "删除楼盘字典");
                    }
                }
            }
            if (type == "3")             {
                if (IDList != null && IDList.Length > 0) 
                {
                    for (int i = 0; i <IDList.Length; i++)
                    {
                        id = _Convert.ToInt(IDList[i], 0);
                        outmsg = ZLDC.Topo.BLL.Estate.EstateBLL.EstateDelAndIsValid(id);

                        ZLDC.Topo.BLL.Estate.OperationlogBLL.p_operationlog_insert("t_estate", id, 2, "删除楼盘字典");
                    }
                }
            }

            int companyId = _Convert.ToInt(_Utility.GetWebConfigSetting("companyId"), 1);   
            int og = 0;
            if (type == "2")
            {
                if (IDList != null && IDList.Length > 0)
                {
                    for (int i = 0; i < IDList.Length; i++)
                    {
                        og++;
                        id = _Convert.ToInt(IDList[i], 0);
                        outmsg = ZLDC.Topo.BLL.Estate.EstateBLL.EstateCheck(id, companyId);
                        
                        ZLDC.Topo.BLL.Estate.OperationlogBLL.p_operationlog_insert("t_estate", id, 2, "审核楼盘字典");
                    }
                }
            }
            if (og > 0)
            {
                outmsg = "审核楼盘字典:"+og+"个";
            }
            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write(outmsg);
            HttpContext.Current.Response.End();
        }


                                private static void EstateDelAll()
        {
            int eid = 0;
            string outmsg = "";
            string[] IDList = _Utility.GetStringBySplit(_Request.GetString("id"), '|');
            int typeid = _Request.GetInt("typeid", 0);

            if (IDList != null && IDList.Length > 0)
            {
                for (int i = 0; i < IDList.Length; i++)
                {
                    eid = _Convert.ToInt(IDList[i], 0);

                    if (typeid == 1)
                    {
                        outmsg = ZLDC.Topo.BLL.Estate.EstateBLL.EstateCheckAll(eid);

                        ZLDC.Topo.BLL.Estate.OperationlogBLL.p_operationlog_insert("t_estate", eid, 2, "审核全部栋阁房号");
                    }

                    if (typeid == 2)
                    {
                        outmsg = ZLDC.Topo.BLL.Estate.EstateBLL.EstateDelAll(eid);

                        ZLDC.Topo.BLL.Estate.OperationlogBLL.p_operationlog_insert("t_estate", eid, 2, "删除全部栋阁房号");
                    }
                }
            }


        }
        
                                private static void DelPic() 
        {

            string outmsg = "";
            int id = _Request.GetInt("id", 0);
            int deptid =_Convert.ToInt(_Utility.GetInfoBySession().m_sDeptID);
            string userid=_Request.GetString("userid","");
            string station = _Utility.GetInfoBySession().m_sStation;
            if (station.Contains("分行经理") ||userid==_Utility.GetInfoBySession().m_sUserID)            {
                outmsg = ZLDC.Topo.BLL.Estate.EstatePicBLL.DelPic(id, deptid);
            }
            else 
            {
                outmsg = "对不起，你无权删除该图片！";
            }
            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write(outmsg);
            HttpContext.Current.Response.End();
        }

                                private static void HousingMSAuto()
        {
            int top = 500;
            string estatename = _Request.GetString("q", "");
            string usage = _Request.GetString("usage", "");     
                        if (estatename.LastIndexOf(',') == estatename.Length - 1)
            {
                HttpContext.Current.Response.Clear();
                HttpContext.Current.Response.Write("");
                HttpContext.Current.Response.End();

                return;
            }
            else
                estatename = estatename.Substring(estatename.LastIndexOf(',') + 1, estatename.Length - estatename.LastIndexOf(',') - 1);

            string json = "";

            if (estatename != "" && estatename != "楼盘名称、拼音均可")
            {
                string condition = " where delFlag=0 and isValid=0 and [level]=1";                      string condition2 = " where delFlag=0 and isValid=0 ";                       
                if (!string.IsNullOrEmpty(estatename))
                {

                    condition += " and (name like '" + estatename + "%' or namepy like '" + estatename + "%' or otherName like '" + estatename + "%' or otherNamePy like '" + estatename + "%' or finalName like '"
    + estatename + "%' or finalNamePy like '" + estatename + "%' )";  
                    
                                                                                                                                                                                                                                                
                        condition2 += " and (name like '" + estatename + "%' or namePy like '" + estatename + "%' or otherName like '"
                            + estatename + "%' or otherNamePy like '" + estatename + "%')";
                    
                }

                                int deptid = _Convert.ToInt(_Utility.GetInfoBySession().m_sDeptID);
                condition += " and " + CacheUtility.Cache_GetAreaByDeptId(deptid);
                condition2 += " and " + CacheUtility.Cache_GetAreaByDeptId(deptid);

                if (usage != "")
                {
                    condition += " and usage in(" + usage + ")";
                    condition2 += " and usage in(" + usage + ")";
                }

                json = ZLDC.Topo.BLL.Estate.BuildBLL.HousingMSAuto(top, condition, condition2);
            }

            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write(json);
            HttpContext.Current.Response.End();
        }

                private static void EstateAutoList()
        {
            int top = 500;
            string estatename = _Request.GetString("q", "");
            string usage = _Request.GetString("usage","");            string json = "";
           
            if (estatename != "" && estatename != "楼盘名称、拼音均可")
            {
                string condition="";
                if (usage != "请选择" && usage != "")
                {
                    condition = " where delFlag=0 and isValid=0 and usage = " + usage;
                }
                else 
                {
                    condition = " where delFlag=0 and isValid=0 ";
                }
                if (!string.IsNullOrEmpty(estatename))
                    condition += " and (name like '" + estatename + "%' or namePy like '" + estatename + "%' or otherName like '" 
                        + estatename + "%' or otherNamePy like '" + estatename + "%' or roadname like '" + estatename + "%')";  
                                int deptid =_Convert.ToInt(_Utility.GetInfoBySession().m_sDeptID);
                condition += " and " + CacheUtility.Cache_GetAreaByDeptId(deptid);

                json = ZLDC.Topo.BLL.Estate.EstateBLL.EstateAutoList(top, condition);
            }

            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write(json);
            HttpContext.Current.Response.End();
        }

                private static void NoEstateAutoList()
        {
            int top = 500;
            string estatename = _Request.GetString("q", "");
            string usage = _Request.GetString("usage","");            string json = "";

            if (estatename != "" && estatename != "楼盘名称、拼音均可")
            {
                string condition="";
                if (usage != "请选择" && usage != "")
                {
                    condition = " where delFlag=0 and isValid=0 and usage = " + usage;
                }
                else
                {
                    condition = " where delFlag=0 and isValid=0 ";
                }
                if (!string.IsNullOrEmpty(estatename))
                    condition += " and (name like '" + estatename + "%' or namePy like '" + estatename + "%' or otherName like '"
                        + estatename + "%' or otherNamePy like '" + estatename + "%' or roadname like '" + estatename + "%')";  
                                                
                json = ZLDC.Topo.BLL.Estate.EstateBLL.EstateAutoList(top, condition);
            }

            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write(json);
            HttpContext.Current.Response.End();
        }

                private static void AllEstateAutoList()
        {
            int top = 100;
            string estatename = _Request.GetString("q", "");
            string usage = _Request.GetString("usage","");            string json = "";

            if (estatename != "" && estatename != "楼盘名称、拼音均可")
            {
                string condition="";
                if (usage != "请选择" && usage != "")
                {
                    condition = " where delFlag=0 and isValid=0 and usage = " + usage;
                }
                else
                {
                    condition = " where delFlag=0 and isValid=0 ";
                }
                if (!string.IsNullOrEmpty(estatename))
                    condition += " and (name like '" + estatename + "%' or namePy like '" + estatename + "%' or otherName like '"
                        + estatename + "%' or otherNamePy like '" + estatename + "%' or roadname like '" + estatename + "%')";  
                json = ZLDC.Topo.BLL.Estate.EstateBLL.EstateAutoList(top, condition);
            }

            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write(json);
            HttpContext.Current.Response.End();
        } 
        
                     private static void BuildAutoNewList()
        {
            int top = 500;
            string estatename = _Request.GetString("q", "");
            string usage = _Request.GetString("usage", "");            string json = "";
            string id = _Request.GetString("id", "0");
            if (estatename != "" && estatename != "楼盘名称、拼音均可")
            {
                string condition = "";
                if (usage != "请选择" && usage != "")
                    condition = " where delFlag=0 and usage in (" + usage + ") ";
                else
                    condition = " where delFlag=0 ";

                if (!string.IsNullOrEmpty(estatename))
                    condition += " and (finalName like '" + estatename + "%' or finalNamePy like '" + estatename + "%' or ename like '" + estatename + "%' or namePy like '" + estatename + "%' )";                  condition += " and eid=" + id ;
                                int deptid = _Convert.ToInt(_Utility.GetInfoBySession().m_sDeptID);
                
                json = ZLDC.Topo.BLL.Estate.BuildBLL.BuildAutonewList(top, condition);
            }

            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write(json);
            HttpContext.Current.Response.End();
        }      
                private static void BuildAutoList()
        {
            int top = 500;
            string estatename = _Request.GetString("q", "");
            string usage = _Request.GetString("usage", "");            string json = "";
            
            if (estatename != "" && estatename != "楼盘名称、拼音均可")
            {
                string condition = "";
                if (usage != "请选择" && usage != "")
                    condition = " where delFlag=0 and usage in (" + usage + ") ";
                else
                    condition = " where delFlag=0 ";

                if (!string.IsNullOrEmpty(estatename))
                    condition += " and (name like '" + estatename + "%' or namePy like '" + estatename + "%' or otherName like '" + estatename + "%' or otherNamePy like '" + estatename + "%' )";  
                                int deptid = _Convert.ToInt(_Utility.GetInfoBySession().m_sDeptID);
                condition += " and " + CacheUtility.Cache_GetAreaByDeptId(deptid);

                json = ZLDC.Topo.BLL.Estate.BuildBLL.BuildAutoList(top, condition);
            }

            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write(json);
            HttpContext.Current.Response.End();
        }      
        
                private static void BuildAutoListString()
        {
            int top = 500;
            string estatename = _Request.GetString("ename", "");

                        if (estatename.LastIndexOf(',') == estatename.Length - 1)
            {
                HttpContext.Current.Response.Clear();
                HttpContext.Current.Response.Write("");
                HttpContext.Current.Response.End();

                return;
            }
            else
                estatename = estatename.Substring(estatename.LastIndexOf(',') + 1, estatename.Length - estatename.LastIndexOf(',') - 1);

            string json = "";

            if (estatename != "" && estatename != "楼盘名称、拼音均可")
            {
                string condition = " where delFlag=0 and isValid=0 ";
                string condition2 = " where delFlag=0 and isValid=0 ";

                if (!string.IsNullOrEmpty(estatename))
                {
                    condition += " and ((otherName + otherNamePy + finalName + finalNamePy like '%" + estatename + "%' ) or (roadname like '" + estatename + "%') or (estate_otherName like '" + estatename + "%'))";                                          condition2 += " and name + namePy + otherName + otherNamePy like '%" + estatename + "%'";
                }

                                int deptid = _Convert.ToInt(_Utility.GetInfoBySession().m_sDeptID);
                condition += " and " + CacheUtility.Cache_GetAreaByDeptId(deptid);
                condition2 += " and " + CacheUtility.Cache_GetAreaByDeptId(deptid);

                json = ZLDC.Topo.BLL.Estate.BuildBLL.BuildAutoListString(top, condition, condition2);
            }            

            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write(json);
            HttpContext.Current.Response.End();
        }

                private static void EnameAutoListString() 
        {
            int top = 500;
            string estatename = _Request.GetString("ename", "");

                        if (estatename.LastIndexOf(',') == estatename.Length - 1)
            {
                HttpContext.Current.Response.Clear();
                HttpContext.Current.Response.Write("");
                HttpContext.Current.Response.End();

                return;
            }
            else
                estatename = estatename.Substring(estatename.LastIndexOf(',') + 1, estatename.Length - estatename.LastIndexOf(',') - 1);

            string json = "";

            if (estatename != "" && estatename != "楼盘名称、拼音均可")
            {
                string condition = " where delFlag=0 and isValid=0 ";

                if (!string.IsNullOrEmpty(estatename))
                    condition += " and otherName + otherNamePy + name + namepy like '%" + estatename + "%'";                  
                json = ZLDC.Topo.BLL.Estate.BuildBLL.EnameAutoList(top, condition);
            }

            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write(json);
            HttpContext.Current.Response.End();
        }

                                private static void buildlist_byeid()
        {            
            string estatename = _Request.GetString("ename", "");    
            string buildname = _Request.GetString("bname", "");

            string useage = _Request.GetString("useage", "");

            string json = "";

            if (!string.IsNullOrEmpty(estatename))
            {
                HttpContext.Current.Session["useage"] = useage;
                                if (buildname != "")
                {
                                        json = CacheUtility.Cache_BuildIdListByEname_Json(estatename,buildname);
                }
                else 
                {
                                        json = CacheUtility.Cache_BuildIdListByEname_Json(estatename);   
                }
            }            

            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write(json);
            HttpContext.Current.Response.End();
        }
                                private static void buildlist_ByEname()
        {
            string estatename = _Request.GetString("ename", "");    
            string buildname = _Request.GetString("q", "");
            string json = "";

            if (!string.IsNullOrEmpty(estatename))
            {
                                if (buildname != "")
                {
                                        json = ZLDC.Topo.BLL.Estate.BuildBLL.BuildIdListByEnameAndBname(estatename, buildname);

                }
                else
                {
                                        json = CacheUtility.Cache_BuildIdListByEnameAndBname_Json(estatename);
                }
            }

            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write(json);
            HttpContext.Current.Response.End();
        }

        #endregion

        #region 栋阁管理

                                private static void BuildList()
        {
            int id = _Request.GetInt("id", 0);
            int page = _Request.GetInt("page", 0);
            int pagesize = _Request.GetInt("pagesize", 0);
            string name = _Request.GetString("name", "");
            int hid = _Request.GetInt("hid", 0);
            string json;
            if (name == "")
            {
                 json = ZLDC.Topo.BLL.Estate.BuildBLL.BuildListLevel(page, pagesize, id);
            }
            else
            {
                 json = ZLDC.Topo.BLL.Estate.BuildBLL.BuildListLevel1(page, pagesize, id, name, hid);
            }

            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write(json);
            HttpContext.Current.Response.End();
        }

        private static void BuildListByName()
        {

            string ename = _Request.GetString("ename", "");
            if (ename == "" || ename == null)
                return;

            int id =_Convert.ToInt(ZLDC.Topo.BLL.Estate.EstateBLL.SelectIdByName(ename));            int page = _Request.GetInt("page", 0);
            int pagesize = _Request.GetInt("pagesize", 0);

            string json = ZLDC.Topo.BLL.Estate.BuildBLL.BuildListLevel(page, pagesize, id);

            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write(json);
            HttpContext.Current.Response.End();
        }

                                private static void BuildSave()
        {
            int id = _Request.GetIntForm("hID", 0);


            string Type = _Request.GetStringForm("sType", "");
            int ActionType = _Request.GetIntForm("ActionType", 0);
            string typeid = _Request.GetStringForm("typeid", "");

            int eid = _Request.GetIntForm("hEID", 0);
            int parentid = _Request.GetIntForm("sBuild", 0);                                        string otherName = _Request.GetStringForm("iOtherName", "");                            string otherNamePy = _Utility.GetChineseSpell(otherName);                               string unit = _Request.GetStringForm("sUnit", "");                                      if (unit == "手填")
                unit = "";

            int floorTotal = _Request.GetIntForm("iFloorTotal", 1);                                 string usage = _Request.GetStringForm("sUsage", "");                                    string remark = _Request.GetStringForm("taRemark", "");                                 int typeId = _Request.GetIntForm("hTypeId", 1);                                         int isvalid = 1;      
                        if (ZLDC.Common.BaseUser.UserInfo.GetPopedom("直接添加栋阁"))
                isvalid = 0;

            string outmsg = "";
            string name = "";
            string namePy = "";
            if (typeId == 1)
            {
                name = _Request.GetStringForm("iName", "") + unit;                                       namePy = _Utility.GetChineseSpell(name);                                 
                if (ActionType == 0)
                {
                    outmsg = ZLDC.Topo.BLL.Estate.BuildBLL.EstateSave(id, name, otherName, namePy, otherNamePy, parentid, usage, floorTotal, "", eid, "", remark, isvalid, _Utility.GetInfoBySession().m_sUserName, _Convert.ToInt(_Utility.GetInfoBySession().m_sUserID), _Utility.GetInfoBySession().m_sDeptName, _Convert.ToInt(_Utility.GetInfoBySession().m_sDeptID),Type);
                }
                else
                {
                    int newid = ZLDC.Topo.BLL.Estate.BuildBLL.EstateAndRoomNOSave(id, name, otherName, namePy, otherNamePy, parentid, usage, floorTotal, "", eid, "", remark, isvalid, _Utility.GetInfoBySession().m_sUserName, _Convert.ToInt(_Utility.GetInfoBySession().m_sUserID), _Utility.GetInfoBySession().m_sDeptName, _Convert.ToInt(_Utility.GetInfoBySession().m_sDeptID),Type);
                    if (newid > 0)                    {
                        string typename = "SqAdd";                          if (ZLDC.Common.BaseUser.UserInfo.GetPopedom("直接添加房号"))
                            typename = "Add";

                        HttpContext.Current.Response.Redirect("../TM/RoomNo.aspx?id=0&value=" + newid + "&type=" + typename + "&Typeid="+typeid+"");                        HttpContext.Current.Response.Write ("<script> self.parent.closeTab(' 添加楼盘');</script>");                    }
                }
            }
            else
            {



                string nameFirst = _Request.GetStringForm("iNameFirst", "");                            string name1 = _Request.GetStringForm("iName1", "0");                                           string name2 = _Request.GetStringForm("iName2", "0");                                           string nameEnd = _Request.GetStringForm("iNameEnd", "");                                if (_Utility.isExists(name1) && _Utility.isExists(name2))                 {
                    int num1 = _Utility.Asc(name1);
                    int num2 = _Utility.Asc(name2);

                    if (num2 > num1) 
                    {
                        for (int i = num1; i <=num2; i++)
                        {
                            name = nameFirst + _Utility.Chr(i).ToString() + nameEnd + unit;
                            namePy = _Utility.GetChineseSpell(name);

                            outmsg = ZLDC.Topo.BLL.Estate.BuildBLL.EstateSave(id, name, otherName, namePy, otherNamePy, parentid, usage, floorTotal, "", eid, "", remark, isvalid, _Utility.GetInfoBySession().m_sUserName, _Convert.ToInt(_Utility.GetInfoBySession().m_sUserID), _Utility.GetInfoBySession().m_sDeptName, _Convert.ToInt(_Utility.GetInfoBySession().m_sDeptID),Type);

                        }
                    }
                    
                }
                else                {
                
                    if (_Convert.ToInt(name2) > _Convert.ToInt(name1))
                    {
                        for (int i = _Convert.ToInt(name1); i <=_Convert.ToInt(name2); i++)
                        {
                            name = nameFirst + i.ToString() + nameEnd + unit;
                            namePy = _Utility.GetChineseSpell(name);

                            outmsg = ZLDC.Topo.BLL.Estate.BuildBLL.EstateSave(id, name, otherName, namePy, otherNamePy, parentid, usage, floorTotal, "", eid, "", remark, isvalid, _Utility.GetInfoBySession().m_sUserName, _Convert.ToInt(_Utility.GetInfoBySession().m_sUserID), _Utility.GetInfoBySession().m_sDeptName, _Convert.ToInt(_Utility.GetInfoBySession().m_sDeptID),Type);
                        }
                    }   
                }
            }



            HttpContext.Current.Response.Clear();
            if (outmsg == "添加成功!" || outmsg=="更新成功!")
            {
                if (typeid == "1")
                {
                    HttpContext.Current.Response.Write("<script> self.parent.closeTab(' 添加楼盘');</script>");                }
                else if (typeid == "2") 
                {
                    HttpContext.Current.Response.Write("<script> self.parent.closeTab(' 申请楼盘');</script>");
                }
                else
                {
                    HttpContext.Current.Response.Write("<script>alert('" + outmsg + "');window.close();</script>");
                }
            }
            else 
            {
                HttpContext.Current.Response.Write("<script>alert('" + outmsg + "');</script>");
            }
        }

                                private static void BuildDetail()
        {
            int id = _Request.GetInt("id", 0);

            string json = ZLDC.Topo.BLL.Estate.BuildBLL.BuildDetail(id);

            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write(json);
            HttpContext.Current.Response.End();
        }

                                private static void SelectNamesById()
        {
            int id = _Request.GetInt("id", 0);

            string json = ZLDC.Topo.BLL.Estate.BuildBLL.SelectNamesById(id);

            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write(json);
            HttpContext.Current.Response.End();
        }

                                private static void SelectNamesByBId()
        {
            int id = _Request.GetInt("id", 0);

            string json = ZLDC.Topo.BLL.Estate.BuildBLL.SelectNamesByBId(id);

            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write(json);
            HttpContext.Current.Response.End();
        }

                                private static void BuildDel()
        {
            int id = 0;
            string outmsg = "";
            string[] IDList = _Utility.GetStringBySplit(_Request.GetString("id"), '|');

            if (IDList != null && IDList.Length > 0)
            {
                for (int i = 0; i < IDList.Length; i++)
                {
                    id = _Convert.ToInt(IDList[i], 0);
                    outmsg = ZLDC.Topo.BLL.Estate.BuildBLL.DelBuild(id);

                    ZLDC.Topo.BLL.Estate.OperationlogBLL.p_operationlog_insert("t_build", id, 2, "删除楼盘字典栋阁");
                }
            }

            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write(outmsg);
            HttpContext.Current.Response.End();
        }
                                private static void BuildDelAndIsValid()
        {
            int id = 0;
            string outmsg = "";
            string[] IDList = _Utility.GetStringBySplit(_Request.GetString("id"), '|');

            if (IDList != null && IDList.Length > 0)
            {
                for (int i = 0; i < IDList.Length; i++)
                {
                    id = _Convert.ToInt(IDList[i], 0);
                    outmsg = ZLDC.Topo.BLL.Estate.BuildBLL.DelBuildAndIsValid(id);

                    ZLDC.Topo.BLL.Estate.OperationlogBLL.p_operationlog_insert("t_build", id, 2, "删除楼盘字典栋阁");
                }
            }

            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write(outmsg);
            HttpContext.Current.Response.End();
        }

                                private static void RoomnoDel()
        {
            int id = 0;
            string outmsg = "";
            string[] IDList = _Utility.GetStringBySplit(_Request.GetString("id"), '|');

            if (IDList != null && IDList.Length > 0)
            {
                for (int i = 0; i < IDList.Length; i++)
                {
                    id = _Convert.ToInt(IDList[i], 0);
                    if (ZLDC.Topo.BLL.Estate.RoomNoBLL.DeleteNameById(id) > 0)
                        outmsg = "房号删除成功";
                    else
                        outmsg = "房号删除失败";

                    ZLDC.Topo.BLL.Estate.OperationlogBLL.p_operationlog_insert("t_roomno", id, 2, "删除楼盘字典房号");
                }
            }

            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write(outmsg);
            HttpContext.Current.Response.End();
        }
                                private static void RoomnoDelAndIsValid()
        {
            int id = 0;
            string outmsg = "";
            string[] IDList = _Utility.GetStringBySplit(_Request.GetString("id"), '|');

            if (IDList != null && IDList.Length > 0)
            {
                for (int i = 0; i < IDList.Length; i++)
                {
                    id = _Convert.ToInt(IDList[i], 0);
                    if (ZLDC.Topo.BLL.Estate.RoomNoBLL.DeleteNameByIdAndIsValid(id) > 0)
                        outmsg = "房号删除成功";
                    else
                        outmsg = "您无权删除有效房号！";

                    ZLDC.Topo.BLL.Estate.OperationlogBLL.p_operationlog_insert("t_roomno", id, 2, "删除楼盘字典房号");
                }
            }

            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write(outmsg);
            HttpContext.Current.Response.End();
        }
        
        #endregion

        #region 楼盘图片

                                private static void EstatePicList()
        {
            int eid = _Request.GetInt("eid", 0);
            int type = _Request.GetInt("type", 0);

            string json = ZLDC.Topo.BLL.Estate.EstatePicBLL.EstatePicList(eid, type);

            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write(json);
            HttpContext.Current.Response.End();
        }
        
        #endregion



        private static void AreaSave1() 
        {
            string areaList = _Request.GetString("area","");
            areaList = areaList.Replace("|", ",");
            int deptid = _Request.GetInt("deptid", 0);
            string name = _Request.GetString("name", "");


            string json = ZLDC.Topo.BLL.Estate.AuthorizationBLL.p_authorization_save1(deptid, name, areaList);
            if (json == "添加成功" || json=="更新成功")             {
                _Cache.Remove("GetAreaByDeptId_AndUse_" + deptid);
                _Cache.Remove("GetAreaByDeptId_" + deptid);
                _Cache.Remove("GetNoAreaByDeptId_" + deptid);

            }
            
            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write(json);
            HttpContext.Current.Response.End();
        }


                                private static void UpdateBuild() 
        {
            string bid = _Request.GetString("id", "0");                                                           int type = _Request.GetInt("type",0);
            string outmsg = "";
           
            if (type == 1)
            {
                int count = ZLDC.Topo.BLL.Estate.RoomNoBLL.SelectRoomNoCountByBid(int.Parse(bid));
                if (count > 0)
                {
                    outmsg = "该栋阁下面存在房号，请先移走，或者删除房号！";
                }
                else
                {
                                                                                                                                                                    outmsg = ZLDC.Topo.BLL.Estate.BuildBLL.DelBuild(int.Parse(bid));
                                   }
            }
            if (type == 2)
            {
                string[] bidlist = bid.Split('|');
                int og = 0;
                if (bidlist.Length > 0)
                {
                    for (int i = 0; i < bidlist.Length-1; i++)
                    {
                        int count = ZLDC.Topo.BLL.Estate.RoomNoBLL.SelectRoomNoCountByBid(int.Parse(bidlist[i]));
                        if (count > 0)
                        {
                            og++;
                        }
                        else
                        {
                                                                                                                                                                                                                                    outmsg = ZLDC.Topo.BLL.Estate.BuildBLL.DelBuild(int.Parse(bidlist[i]));
                                                    }
                    }
                    if (og > 0)
                    {
                        outmsg = "未删除："+og+"个栋阁，请先移除房号或者下级栋阁!";
                    }
                }

            }
            #region 批量审核

            if (type == 3)
            {
                string[] bidlist = bid.Split('|');
                int og = 0;
               
                string buildid = "";
                if (bidlist.Length > 0)
                {
                    for (int i = 0; i < bidlist.Length - 1; i++)
                    {
                        og++;
                        if (i == bidlist.Length - 2)
                        {
                            buildid += bidlist[i] ;
                        }
                        else
                        {
                            buildid += bidlist[i] + ",";
                        }
                    }
                }
                string sql = "update t_build set isvalid=0 where id in("+buildid+")";
                outmsg = ZLDC.Topo.BLL.Estate.BuildBLL.SHBuild(sql);
                if (og > 0)
                {
                    outmsg = "审核：" + og + "个栋阁!";
                }
            }
            #endregion
                
            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write(outmsg);
            HttpContext.Current.Response.End();

            
        }
                private static void UpdateBuildParentId() 
        {
            int id = _Request.GetInt("id", 0);
            int parentId = 0;
            if (id == 0)
                return;

            string outmsg = ZLDC.Topo.BLL.Estate.BuildBLL.UpdateParentIdById(id,parentId);

            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write(outmsg);
            HttpContext.Current.Response.End();
        }
                                private static void RemoveBuildParentId()
        {
            int parentId = _Request.GetInt("parentId", 0);            string outmsg = "";
            string [] IDList =_Utility.GetStringBySplit(_Request.GetString("id", ""),'|');
            if (IDList != null && IDList.Length > 0)
            {

                for (int i = 0; i < IDList.Length; i++)
                {
                    int id = _Convert.ToInt(IDList[i], 0);

                    outmsg = ZLDC.Topo.BLL.Estate.BuildBLL.UpdateParentIdById(id,parentId);
                }

            }
            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write(outmsg);
            HttpContext.Current.Response.End();
        }

                                private static void UpateEstate()
        {
            int id = _Request.GetInt("id", 0);                string outmsg = "";

            outmsg = ZLDC.Topo.BLL.Estate.EstateBLL.UpateEstate(id);

            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write(outmsg);
            HttpContext.Current.Response.End();
        }        

        private static void RemoveRoomNoByBId()
        {
            int bid = _Request.GetInt("bid", 0);            string outmsg = "";
            string [] IDList =_Utility.GetStringBySplit(_Request.GetString("id", ""),'|');
            if (IDList != null && IDList.Length > 0)
            {

                for (int i = 0; i < IDList.Length; i++)
                {
                    int id = _Convert.ToInt(IDList[i], 0);
                    string roomno = ZLDC.Topo.BLL.Estate.BuildBLL.ExistsRoomNo(id, bid);                    if (roomno == "")
                    {
                        outmsg = ZLDC.Topo.BLL.Estate.BuildBLL.RemoveRoomNoByBid(id, bid);
                    }
                    else 
                    {
                        outmsg = "此栋阁里面已存在相同的房号！";
                    }
                    
                }

            }
            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write(outmsg);
            HttpContext.Current.Response.End();
        }
    }
}
